<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Banana;

class BananaSearchController extends Controller
{
    /**
     * bananas列表
     */
    public function index(Request $request)
    {
        if($request->has('titlesearch')){
            $bananas = Banana::search($request->titlesearch)
                     ->paginate(6);
        }else{
            $bananas = Banana::paginate(6);
        }
        return view('banana-search',compact('bananas'));
    }

    /**
     * 创建新的banana
     */
    public function create(Request $request)
    {
        $this->validate($request,['title'=>'required']);

        $bananas = Banana::create($request->all());
        return back();
    }
}
